14. 解决方案:练习题
** 这里是一种解法:**
** 问题:** 编写一个名为director_win的函数,它接受2个参数,winners字典和导演名称。它应该返回与导演相对应的奥斯卡奖的数量。
# function that takes the winners dictionary and the director name as arguments and returns win counts
def director_win(winners, director_name):
win_count_dict = {}
for year, winnerlist in winners.items():
for winner in winnerlist:
win_count_dict[winner] = win_count_dict.get(winner,0)+1
if director_name in win_count_dict:
return (win_count_dict[director_name])
else:
return 0